package luceneqe.modelsIR.clauses;

import java.io.IOException;


import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.search.Similarity;
import org.apache.lucene.search.Weight;

@SuppressWarnings("serial")
public class BM25MultiClauseWeight  implements Weight{

	private String boostedQuery;
	private Query query;
	private Similarity similarity;
	private String[] fields;
	private BM25MultiClauseQuery.BooleanQuery queryType;

	public BM25MultiClauseWeight(Query query, Searcher searcher, String[] fields,BM25MultiClauseQuery.BooleanQuery queryType, String boostedQuery) {
		this.query = query;
		this.similarity = searcher.getSimilarity();
		this.fields = fields;
		this.queryType = queryType;
		this.boostedQuery = boostedQuery;
	}

	public Explanation explain(IndexReader reader, int doc) throws IOException {
		Explanation exp = new Explanation();
		exp = new Explanation(25f, "Weight");
		exp.addDetail(new BM25MultiClauseScorer(this.similarity, this.query,
				this.fields, reader,this.queryType, this.boostedQuery).explain(doc));
		return exp;
	}

	public Query getQuery() {
		// TODO Auto-generated method stub
		return this.query;
	}
	
	public float getValue() {
		return 1.0f;
	}

	public void normalize(float norm) {

	}

	public Scorer scorer(IndexReader reader) throws IOException {
		return new BM25MultiClauseScorer(this.similarity, this.query,
				this.fields, reader,this.queryType, this.boostedQuery);
	}

	public float sumOfSquaredWeights() throws IOException {
		return 1.0f;
	}

}

